package main

import (
	"fmt"
	"golang.org/x/crypto/bcrypt"

	//"fox/faker"
	"io"
	"net/http"
	"os"
)

func main() {

	str := []byte("111")
	hash, err := bcrypt.GenerateFromPassword(str, bcrypt.MinCost)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(hash))

	err = bcrypt.CompareHashAndPassword(hash, str)
	if err != nil {
		panic(err)
	}
	fmt.Println("校验通过")

}

func DownLoad() {
	var (
		url  string
		resp *http.Response
		buf  []byte
		n    int
		file *os.File
		path string
		err  error
	)

	url = "https://raw.githubusercontent.com/modood/Administrative-divisions-of-China/master/dist/streets.json"

	resp, err = http.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	path, _ = os.Getwd()

	file, err = os.OpenFile(path+"/faker/streets.json", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
	if err != nil {
		panic(err)
	}

	buf = make([]byte, 4096)

	for {
		n, err = resp.Body.Read(buf)
		if n == 0 {
			break
		}
		if err != nil && err != io.EOF {
			return
		}
		//result += string(buf[:n])
		file.Write(buf[:n])
	}
	file.Close()
	fmt.Println("写入完成")
}
